<?php

use Symfony\Component\Translation\Interval;

class GroupHelper {
    /**
     * Retrieve collection of groups that are not superior than the current user's one
     * @author Trung Vuong
     * @return mixed Collection or array
     */
    public static function nonSuperiorGroups() {
        $user = Sentry::getUser();
        if (!empty($user)) {
            $groups = $user->getGroups();
            if (!$groups->isEmpty()) {
                return Group::where('id', '>=', $groups[0]->getId())->get();
            }
        }
        return array();
    }
    
    /**
     * Generate array of groups as select options
     * @author Trung Vuong
     * @param mixed $groups null or Collection
     * @return array
     */
    public static function options($groups = null) {
        if (!is_object($groups)) {
            $groups = Sentry::findAllGroups();
        }
        
        $options = array();
        foreach ($groups as $group) {
            $options[ $group->getId() ] = Lang::get("group.name.{$group->getName()}");
        }
        return $options;
    }
    
      /**
     * get Role name by id
     * @author Thuan Truong
     * @param id
     * @return string
     */
    public static function getRoleName($id) {
        $role = Group::find($id);
        if ($role)
            return $role->name;
        return 0;
    }
}